package model

import (
	"fmt"
	"time"
)

type ReaderInOutLogTemp struct {
	ID          int       `xorm:"pk autoincr 'nID'"`
	RecordTime  time.Time `xorm:"'dtRecordTime'"`
	Type        int       `xorm:"'nType'"`
	Counter     int       `xorm:"not null default 0 'nCounter'"`
	JanitorName string    `xorm:"'szJanitorName'"`
	ReaderID    string    `xorm:"'szReaderID'"`
}

func (r *ReaderInOutLogTemp) TableName() string {
	return "ReaderINOUTLog_temp"
}

// GetBook retrieves a record by ID from the database.
func GetReaderInOutLogTempById(id int) (*ReaderInOutLogTemp, int) {
	record := new(ReaderInOutLogTemp)
	has, err := db.ID(id).Get(record)
	if err != nil {
		fmt.Printf("Error ReaderInOutLogTemp getting record: %v", err)
		return nil, 500
	}
	if !has {
		return nil, 404
	}
	return record, 200
}

func GetReaderInOutLogTempIds() ([]int, int) {
	var nids []int
	err := db.Table("ReaderINOUTLog_temp").Cols("nID").Find(&nids)
	if err != nil {
		fmt.Printf("Error ReaderInOutLogTemp getting record: %v", err)
		return nil, 500
	}
	return nids, 200
}

// delete
func DeleteReaderInOutLogTempById(id int) int {
	_, err := db.ID(id).Delete(&ReaderInOutLogTemp{})
	if err != nil {
		fmt.Printf("Error ReaderInOutLogTemp delete record: %v", err)
		return 500
	}
	return 200
}
